load("@io_bazel_rules_go//go:def.bzl", "go_binary", "go_library", "go_test")

go_library(
    name = "tidb-server_lib",
    srcs = ["main.go"],
    importpath = "github.com/pingcap/tidb/tidb-server",
    visibility = ["//visibility:private"],
    deps = [
        "//bindinfo",
        "//config",
        "//ddl",
        "//domain",
        "//executor",
        "//executor/mppcoordmanager",
        "//extension",
        "//extension/_import",
        "//keyspace",
        "//kv",
        "//metrics",
        "//parser/mysql",
        "//parser/terror",
        "//parser/types",
        "//planner/core",
        "//plugin",
        "//privilege/privileges",
        "//resourcemanager",
        "//server",
        "//session",
        "//session/txninfo",
        "//sessionctx/binloginfo",
        "//sessionctx/variable",
        "//statistics",
        "//store",
        "//store/copr",
        "//store/driver",
        "//store/mockstore",
        "//tidb-binlog/pump_client",
        "//util",
        "//util/chunk",
        "//util/cpuprofile",
        "//util/deadlockhistory",
        "//util/disk",
        "//util/domainutil",
        "//util/kvcache",
        "//util/logutil",
        "//util/memory",
        "//util/metricsutil",
        "//util/printer",
        "//util/sem",
        "//util/signal",
        "//util/stmtsummary/v2:stmtsummary",
        "//util/sys/linux",
        "//util/sys/storage",
        "//util/systimemon",
        "//util/tiflashcompute",
        "//util/topsql",
        "//util/versioninfo",
        "@com_github_opentracing_opentracing_go//:opentracing-go",
        "@com_github_pingcap_errors//:errors",
        "@com_github_pingcap_failpoint//:failpoint",
        "@com_github_pingcap_log//:log",
        "@com_github_prometheus_client_golang//prometheus",
        "@com_github_prometheus_client_golang//prometheus/push",
        "@com_github_tikv_client_go_v2//tikv",
        "@com_github_tikv_client_go_v2//txnkv/transaction",
        "@com_github_tikv_pd_client//:client",
        "@org_uber_go_automaxprocs//maxprocs",
        "@org_uber_go_zap//:zap",
    ],
)

go_binary(
    name = "tidb-server",
    embed = [":tidb-server_lib"],
    visibility = ["//visibility:public"],
    x_defs = {
        "github.com/pingcap/tidb/parser/mysql.TiDBReleaseVersion": "{STABLE_TiDB_RELEASE_VERSION}",
        "github.com/pingcap/tidb/util/versioninfo.TiDBBuildTS": "{STABLE_TiDB_BUILD_UTCTIME}",
        "github.com/pingcap/tidb/util/versioninfo.TiDBGitHash": "{STABLE_TIDB_GIT_HASH}",
        "github.com/pingcap/tidb/util/versioninfo.TiDBEnterpriseExtensionGitHash": "{STABLE_TIDB_ENTERPRISE_EXTENSION_GIT_HASH}",
        "github.com/pingcap/tidb/util/versioninfo.TiDBGitBranch": "{STABLE_TIDB_GIT_BRANCH}",
        "github.com/pingcap/tidb/util/versioninfo.TiDBEdition": "{STABLE_TIDB_EDITION}",
    },
)

go_binary(
    name = "tidb-server-check",
    embed = [":tidb-server_lib"],
    gc_linkopts = [
        "-X",
        "github.com/pingcap/tidb/config.checkBeforeDropLDFlag=1",
    ],
    visibility = ["//visibility:public"],
)

go_test(
    name = "tidb-server_test",
    timeout = "short",
    srcs = ["main_test.go"],
    embed = [":tidb-server_lib"],
    flaky = True,
    deps = [
        "//config",
        "//parser/mysql",
        "//sessionctx/variable",
        "//testkit/testsetup",
        "@com_github_stretchr_testify//require",
        "@io_opencensus_go//stats/view",
        "@org_uber_go_goleak//:goleak",
    ],
)
